package com.napenalki.toto.domain;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import org.hibernate.validator.constraints.Email;

@Entity
@Table(name = "USER")
public class User {

    private String userName;
    private String password;
    private String email;
    private String displayName;
    private String role;
    private int points = 0;
    private List<Prediction> predictions;
    
    public User() {        
    }

    public User(String userName) {
        this(userName, null, null, null, 0);
    }

    public User(String userName, String password, String email,
        String displayName, int points) {
        this(userName, password, email, displayName, "USER", points);
    }
    
    public User(String userName, String password, String email,
            String displayName, String role, int points) {
        super();
        this.userName = userName;
        this.password = password;
        this.email = email;
        this.displayName = displayName;
        this.role = role;
        this.points = points;
    }

    @Id
    @Column(name = "USER_NAME")
    @NotNull
    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    @Column(name = "PASSWORD")
    @NotNull
    @Size(min = 6)
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Column(name = "EMAIL")
    @NotNull
    @Email
    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @Column(name = "DISPLAY_NAME")
    @NotNull
    public String getDisplayName() {
        return displayName;
    }

    public void setDisplayName(String displayName) {
        this.displayName = displayName;
    }

    @Column(name = "ROLE")
    public String getRole() {
        return role;
    }

    public void setRole(String role) {
        this.role = role;
    }

    @Column(name = "POINTS")
    @Min(0)
    public int getPoints() {
        return points;
    }

    public void setPoints(int points) {
        this.points = points;
    }

    @OneToMany(mappedBy = "user", cascade = CascadeType.ALL)
    public List<Prediction> getPredictions() {
        return predictions;
    }

    public void setPredictions(List<Prediction> predictions) {
        this.predictions = predictions;
    }
}
